const express = require('express');
const router = express.Router();
const projectController = require('../controllers/projectController');

/**
 * @swagger
 * tags:
 *   name: 项目管理
 *   description: 项目表 CRUD 接口
 */

/**
 * @swagger
 * /api/projects:
 *   post:
 *     summary: 创建新的项目
 *     tags: [项目管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *               projectManager: { type: integer }
 *               builder: { type: integer }
 *               laborTeam: { type: integer }
 *               remark: { type: string }
 *               status: { type: integer }
 *     responses:
 *       200:
 *         description: 创建成功
 */
router.post('/', projectController.createProject);

/**
 * @swagger
 * /api/projects:
 *   get:
 *     summary: 获取所有项目
 *     tags: [项目管理]
 *     responses:
 *       200:
 *         description: 返回项目列表
 */
router.get('/', projectController.getAllProjects);

/**
 * @swagger
 * /api/projects/{id}:
 *   get:
 *     summary: 根据ID获取项目详情
 *     tags: [项目管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 项目ID
 *     responses:
 *       200:
 *         description: 成功返回项目详情
 *       404:
 *         description: 项目不存在
 */
router.get('/:id', projectController.getProjectById);

/**
 * @swagger
 * /api/projects/{id}:
 *   put:
 *     summary: 更新项目
 *     tags: [项目管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 项目ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *               projectManager: { type: integer }
 *               builder: { type: integer }
 *               laborTeam: { type: integer }
 *               remark: { type: string }
 *               ended_at: { type: string, format: date-time }
 *               status: { type: integer }
 *     responses:
 *       200:
 *         description: 更新成功
 */
router.put('/:id', projectController.updateProject);

/**
 * @swagger
 * /api/projects/{id}:
 *   delete:
 *     summary: 删除项目（软删除）
 *     tags: [项目管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 项目ID
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete('/:id', projectController.deleteProject);

module.exports = router;
